import os
import django
import sys

# 设置Django环境
sys.path.append('d:\\test\\cdn-preheat')
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'cdn_preheat.settings')
django.setup()

from preheat.models import ManualPreheat

# 要检查的任务ID
task_id = '93f44699-3c00-4129-8537-015c637d9f62'

try:
    # 从数据库获取任务
    task = ManualPreheat.objects.get(id=task_id)
    
    # 打印任务详细信息
    print(f"任务ID: {task.id}")
    print(f"任务名称: {task.name}")
    print(f"任务状态: {task.status}")
    print(f"创建时间: {task.created_time}")
    print(f"完成时间: {task.completed_time}")
    print(f"是否有failed_urls: {task.failed_urls is not None}")
    if task.failed_urls:
        newline = '\n'
        print(f"失败URL数量: {len(task.failed_urls.split(newline))}")
        print(f"失败URL内容: {task.failed_urls}")
    
    # 检查Completed字段的计算
    completed = task.status == 'completed'
    print(f"根据status计算的completed值: {completed}")
    
    # 列出所有ManualPreheat任务的状态分布
    print("\n所有ManualPreheat任务状态分布:")
    status_counts = ManualPreheat.objects.values('status').annotate(count=django.db.models.Count('id'))
    for status in status_counts:
        print(f"  {status['status']}: {status['count']}")
    
except ManualPreheat.DoesNotExist:
    print(f"任务 {task_id} 不存在")
    # 列出所有可用的任务ID
    print("\n所有可用的任务ID:")
    for task in ManualPreheat.objects.all():
        print(f"  {task.id} - {task.status} - {task.created_time}")
except Exception as e:
    print(f"发生错误: {e}")